var mongoose = require('mongoose');
var bcrypt = require('bcrypt');

var UserSchema = new mongoose.Schema({
	name: {type: String, required: true},
	username: {type: String, unique: true, required: true},
	email: {type: String, unique:true, required: true},
	password: {type: String, required: true}
})

UserSchema.methods.genHash = function(password){
	var salt = bcrypt.genSaltSync(9);
	var hash = bcrypt.hashSync(password, salt);
	return hash;
}
UserSchema.methods.verifyPassword = function(password){
	return bcrypt.compareSync(password, this.password);
}
module.exports = mongoose.model('User', UserSchema);